//
//  WelcomeViewController.m
//  鱼鱼APP
//
//  Created by User on 15/1/12.
//  Copyright (c) 2015年 User. All rights reserved.
//

#import "WelcomeViewController.h"
#import "AppDelegate.h"
#import "TotalViewController.h"

@interface WelcomeViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIPageControl *pageCon;

@end

@implementation WelcomeViewController

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    [self setPageCon:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
 
    NSMutableArray *welcomeArray = [[NSMutableArray alloc]initWithObjects:@"s0",@"s1",@"s2",@"s3",@"s4", nil];
    
   UIScrollView *welcomeScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT)];
    welcomeScrollView.pagingEnabled = TRUE;
    welcomeScrollView.backgroundColor = [UIColor whiteColor];
    welcomeScrollView.delegate = self;
    welcomeScrollView.contentSize = CGSizeMake(SCREEN_WIDTH * [welcomeArray count], SCREEN_HEIGHT);
    welcomeScrollView.showsVerticalScrollIndicator = FALSE;
    welcomeScrollView.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:welcomeScrollView];
    
    for( int i = 0; i < [welcomeArray count];i++ )
    {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake( SCREEN_WIDTH * i , 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT)];
        
        imageView.image = [UIImage imageNamed:[welcomeArray objectAtIndex:i]];
        [welcomeScrollView addSubview:imageView];
        if(i == 4)
        {
            imageView.userInteractionEnabled = TRUE;
            UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonEnterTapped:)];
            [imageView addGestureRecognizer:gesture];
        }
    }
    
    
    _pageCon = [[UIPageControl alloc]initWithFrame:CGRectMake(0.0f, SCREEN_HEIGHT - 40.0f, SCREEN_WIDTH, 30.0f)];
    _pageCon.currentPage = 0;
    _pageCon.numberOfPages = [welcomeArray count];
    self.pageCon.enabled = FALSE;
    [self.view addSubview:self.pageCon];
}

- (void)buttonEnterTapped:(id)sender
{
    [[UIApplication sharedApplication]setStatusBarHidden:FALSE];
    
    TotalViewController *totalViewCon = [[TotalViewController alloc]init];
    [self.navigationController pushViewController:totalViewCon animated:FALSE];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int currentPage = scrollView.contentOffset.x / SCREEN_WIDTH;
    self.pageCon.currentPage = currentPage;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
